/*
 * Copyright (C) 2020 Spreadtrum Communications Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include "sprd_panel.h"
#include "sprd_dsi.h"
#include "dsi/mipi_dsi_api.h"
#include "sprd_dphy.h"
#include "../bitfile/lattice_rm67200.h"
#include "../bitfile/lattice_rm67200_single.h"

#ifdef CONFIG_SPI_FPGA
extern bool dual_lcd_display;
#endif

#if 0
static uint8_t init_data[] = {
	0x29, 0x00, 0x00,  0x02, 0xFE, 0x21,
	0x29, 0x00, 0x00,  0x02, 0x04, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x00, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x2A, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x26, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x54, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x50, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x7B, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x77, 0x00,
	0x29, 0x00, 0x00,  0x02, 0xA2, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x9D, 0x00,
	0x29, 0x00, 0x00,  0x02, 0xC9, 0x00,
	0x29, 0x00, 0x00,  0x02, 0xC5, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x01, 0x0C,
	0x29, 0x00, 0x00,  0x02, 0x27, 0x0C,
	0x29, 0x00, 0x00,  0x02, 0x51, 0x0C,
	0x29, 0x00, 0x00,  0x02, 0x78, 0x0C,
	0x29, 0x00, 0x00,  0x02, 0x9E, 0x0C,
	0x29, 0x00, 0x00,  0x02, 0xC6, 0x0C,
	0x29, 0x00, 0x00,  0x02, 0x02, 0x25,
	0x29, 0x00, 0x00,  0x02, 0x28, 0x25,
	0x29, 0x00, 0x00,  0x02, 0x52, 0x25,
	0x29, 0x00, 0x00,  0x02, 0x79, 0x25,
	0x29, 0x00, 0x00,  0x02, 0x9F, 0x25,
	0x29, 0x00, 0x00,  0x02, 0xC7, 0x25,
	0x29, 0x00, 0x00,  0x02, 0x03, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0x29, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0x53, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0x7A, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0xA0, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0xC8, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0x09, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x05, 0x4E,
	0x29, 0x00, 0x00,  0x02, 0x31, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x2B, 0x4E,
	0x29, 0x00, 0x00,  0x02, 0x5A, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x55, 0x4E,
	0x29, 0x00, 0x00,  0x02, 0x80, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x7C, 0x4E,
	0x29, 0x00, 0x00,  0x02, 0xA7, 0x00,
	0x29, 0x00, 0x00,  0x02, 0xA3, 0x4E,
	0x29, 0x00, 0x00,  0x02, 0xCE, 0x00,
	0x29, 0x00, 0x00,  0x02, 0xCA, 0x4E,
	0x29, 0x00, 0x00,  0x02, 0x06, 0x60,
	0x29, 0x00, 0x00,  0x02, 0x2D, 0x60,
	0x29, 0x00, 0x00,  0x02, 0x56, 0x60,
	0x29, 0x00, 0x00,  0x02, 0x7D, 0x60,
	0x29, 0x00, 0x00,  0x02, 0xA4, 0x60,
	0x29, 0x00, 0x00,  0x02, 0xCB, 0x60,
	0x29, 0x00, 0x00,  0x02, 0x07, 0x70,
	0x29, 0x00, 0x00,  0x02, 0x2F, 0x70,
	0x29, 0x00, 0x00,  0x02, 0x58, 0x70,
	0x29, 0x00, 0x00,  0x02, 0x7E, 0x70,
	0x29, 0x00, 0x00,  0x02, 0xA5, 0x70,
	0x29, 0x00, 0x00,  0x02, 0xCC, 0x70,
	0x29, 0x00, 0x00,  0x02, 0x08, 0x7E,
	0x29, 0x00, 0x00,  0x02, 0x30, 0x7E,
	0x29, 0x00, 0x00,  0x02, 0x59, 0x7E,
	0x29, 0x00, 0x00,  0x02, 0x7F, 0x7E,
	0x29, 0x00, 0x00,  0x02, 0xA6, 0x7E,
	0x29, 0x00, 0x00,  0x02, 0xCD, 0x7E,
	0x29, 0x00, 0x00,  0x02, 0x0E, 0x01,
	0x29, 0x00, 0x00,  0x02, 0x0A, 0x8D,
	0x29, 0x00, 0x00,  0x02, 0x36, 0x01,
	0x29, 0x00, 0x00,  0x02, 0x32, 0x8D,
	0x29, 0x00, 0x00,  0x02, 0x5F, 0x01,
	0x29, 0x00, 0x00,  0x02, 0x5B, 0x8D,
	0x29, 0x00, 0x00,  0x02, 0x85, 0x01,
	0x29, 0x00, 0x00,  0x02, 0x81, 0x8D,
	0x29, 0x00, 0x00,  0x02, 0xAD, 0x01,
	0x29, 0x00, 0x00,  0x02, 0xA9, 0x8D,
	0x29, 0x00, 0x00,  0x02, 0xD3, 0x01,
	0x29, 0x00, 0x00,  0x02, 0xCF, 0x8D,
	0x29, 0x00, 0x00,  0x02, 0x0B, 0xBB,
	0x29, 0x00, 0x00,  0x02, 0x33, 0xBB,
	0x29, 0x00, 0x00,  0x02, 0x5C, 0xBB,
	0x29, 0x00, 0x00,  0x02, 0x82, 0xBB,
	0x29, 0x00, 0x00,  0x02, 0xAA, 0xBB,
	0x29, 0x00, 0x00,  0x02, 0xD0, 0xBB,
	0x29, 0x00, 0x00,  0x02, 0x0C, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0x34, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0x5D, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0x83, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0xAB, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0xD1, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0x0D, 0x1A,
	0x29, 0x00, 0x00,  0x02, 0x35, 0x1A,
	0x29, 0x00, 0x00,  0x02, 0x5E, 0x1A,
	0x29, 0x00, 0x00,  0x02, 0x84, 0x1A,
	0x29, 0x00, 0x00,  0x02, 0xAC, 0x1A,
	0x29, 0x00, 0x00,  0x02, 0xD2, 0x1A,
	0x29, 0x00, 0x00,  0x02, 0x13, 0x55,
	0x29, 0x00, 0x00,  0x02, 0x0F, 0x46,
	0x29, 0x00, 0x00,  0x02, 0x3B, 0x55,
	0x29, 0x00, 0x00,  0x02, 0x37, 0x46,
	0x29, 0x00, 0x00,  0x02, 0x64, 0x55,
	0x29, 0x00, 0x00,  0x02, 0x60, 0x46,
	0x29, 0x00, 0x00,  0x02, 0x8A, 0x55,
	0x29, 0x00, 0x00,  0x02, 0x86, 0x46,
	0x29, 0x00, 0x00,  0x02, 0xB2, 0x55,
	0x29, 0x00, 0x00,  0x02, 0xAE, 0x46,
	0x29, 0x00, 0x00,  0x02, 0xD8, 0x55,
	0x29, 0x00, 0x00,  0x02, 0xD4, 0x46,
	0x29, 0x00, 0x00,  0x02, 0x10, 0x8A,
	0x29, 0x00, 0x00,  0x02, 0x38, 0x8A,
	0x29, 0x00, 0x00,  0x02, 0x61, 0x8A,
	0x29, 0x00, 0x00,  0x02, 0x87, 0x8A,
	0x29, 0x00, 0x00,  0x02, 0xAF, 0x8A,
	0x29, 0x00, 0x00,  0x02, 0xD5, 0x8A,
	0x29, 0x00, 0x00,  0x02, 0x11, 0xC1,
	0x29, 0x00, 0x00,  0x02, 0x39, 0xC1,
	0x29, 0x00, 0x00,  0x02, 0x62, 0xC1,
	0x29, 0x00, 0x00,  0x02, 0x88, 0xC1,
	0x29, 0x00, 0x00,  0x02, 0xB0, 0xC1,
	0x29, 0x00, 0x00,  0x02, 0xD6, 0xC1,
	0x29, 0x00, 0x00,  0x02, 0x12, 0xC2,
	0x29, 0x00, 0x00,  0x02, 0x3A, 0xC2,
	0x29, 0x00, 0x00,  0x02, 0x63, 0xC2,
	0x29, 0x00, 0x00,  0x02, 0x89, 0xC2,
	0x29, 0x00, 0x00,  0x02, 0xB1, 0xC2,
	0x29, 0x00, 0x00,  0x02, 0xD7, 0xC2,
	0x29, 0x00, 0x00,  0x02, 0x18, 0x6A,
	0x29, 0x00, 0x00,  0x02, 0x14, 0xF7,
	0x29, 0x00, 0x00,  0x02, 0x42, 0x6A,
	0x29, 0x00, 0x00,  0x02, 0x3D, 0xF7,
	0x29, 0x00, 0x00,  0x02, 0x69, 0x6A,
	0x29, 0x00, 0x00,  0x02, 0x65, 0xF7,
	0x29, 0x00, 0x00,  0x02, 0x8F, 0x6A,
	0x29, 0x00, 0x00,  0x02, 0x8B, 0xF7,
	0x29, 0x00, 0x00,  0x02, 0xB7, 0x6A,
	0x29, 0x00, 0x00,  0x02, 0xB3, 0xF7,
	0x29, 0x00, 0x00,  0x02, 0xDD, 0x6A,
	0x29, 0x00, 0x00,  0x02, 0xD9, 0xF7,
	0x29, 0x00, 0x00,  0x02, 0x15, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0x3F, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0x66, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0x8C, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0xB4, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0xDA, 0x3B,
	0x29, 0x00, 0x00,  0x02, 0x16, 0x67,
	0x29, 0x00, 0x00,  0x02, 0x40, 0x67,
	0x29, 0x00, 0x00,  0x02, 0x67, 0x67,
	0x29, 0x00, 0x00,  0x02, 0x8D, 0x67,
	0x29, 0x00, 0x00,  0x02, 0xB5, 0x67,
	0x29, 0x00, 0x00,  0x02, 0xDB, 0x67,
	0x29, 0x00, 0x00,  0x02, 0x17, 0xA7,
	0x29, 0x00, 0x00,  0x02, 0x41, 0xA7,
	0x29, 0x00, 0x00,  0x02, 0x68, 0xA7,
	0x29, 0x00, 0x00,  0x02, 0x8E, 0xA7,
	0x29, 0x00, 0x00,  0x02, 0xB6, 0xA7,
	0x29, 0x00, 0x00,  0x02, 0xDC, 0xA7,
	0x29, 0x00, 0x00,  0x02, 0x1D, 0xBF,
	0x29, 0x00, 0x00,  0x02, 0x19, 0xD1,
	0x29, 0x00, 0x00,  0x02, 0x47, 0xBF,
	0x29, 0x00, 0x00,  0x02, 0x43, 0xD1,
	0x29, 0x00, 0x00,  0x02, 0x6E, 0xBF,
	0x29, 0x00, 0x00,  0x02, 0x6A, 0xD1,
	0x29, 0x00, 0x00,  0x02, 0x94, 0xBF,
	0x29, 0x00, 0x00,  0x02, 0x90, 0xD1,
	0x29, 0x00, 0x00,  0x02, 0xBC, 0xBF,
	0x29, 0x00, 0x00,  0x02, 0xB8, 0xD1,
	0x29, 0x00, 0x00,  0x02, 0xE2, 0xBF,
	0x29, 0x00, 0x00,  0x02, 0xDE, 0xD1,
	0x29, 0x00, 0x00,  0x02, 0x1A, 0x0A,
	0x29, 0x00, 0x00,  0x02, 0x44, 0x0A,
	0x29, 0x00, 0x00,  0x02, 0x6B, 0x0A,
	0x29, 0x00, 0x00,  0x02, 0x91, 0x0A,
	0x29, 0x00, 0x00,  0x02, 0xB9, 0x0A,
	0x29, 0x00, 0x00,  0x02, 0xDF, 0x0A,
	0x29, 0x00, 0x00,  0x02, 0x1B, 0x19,
	0x29, 0x00, 0x00,  0x02, 0x45, 0x19,
	0x29, 0x00, 0x00,  0x02, 0x6C, 0x19,
	0x29, 0x00, 0x00,  0x02, 0x92, 0x19,
	0x29, 0x00, 0x00,  0x02, 0xBA, 0x19,
	0x29, 0x00, 0x00,  0x02, 0xE0, 0x19,
	0x29, 0x00, 0x00,  0x02, 0x1C, 0x2E,
	0x29, 0x00, 0x00,  0x02, 0x46, 0x2E,
	0x29, 0x00, 0x00,  0x02, 0x6D, 0x2E,
	0x29, 0x00, 0x00,  0x02, 0x93, 0x2E,
	0x29, 0x00, 0x00,  0x02, 0xBB, 0x2E,
	0x29, 0x00, 0x00,  0x02, 0xE1, 0x2E,
	0x29, 0x00, 0x00,  0x02, 0x22, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x1E, 0x45,
	0x29, 0x00, 0x00,  0x02, 0x4C, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x48, 0x45,
	0x29, 0x00, 0x00,  0x02, 0x73, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x6F, 0x45,
	0x29, 0x00, 0x00,  0x02, 0x99, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x95, 0x45,
	0x29, 0x00, 0x00,  0x02, 0xC1, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0xBD, 0x45,
	0x29, 0x00, 0x00,  0x02, 0xE7, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0xE3, 0x45,
	0x29, 0x00, 0x00,  0x02, 0x1F, 0x5C,
	0x29, 0x00, 0x00,  0x02, 0x49, 0x5C,
	0x29, 0x00, 0x00,  0x02, 0x70, 0x5C,
	0x29, 0x00, 0x00,  0x02, 0x96, 0x5C,
	0x29, 0x00, 0x00,  0x02, 0xBE, 0x5C,
	0x29, 0x00, 0x00,  0x02, 0xE4, 0x5C,
	0x29, 0x00, 0x00,  0x02, 0x20, 0x7C,
	0x29, 0x00, 0x00,  0x02, 0x4A, 0x7C,
	0x29, 0x00, 0x00,  0x02, 0x71, 0x7C,
	0x29, 0x00, 0x00,  0x02, 0x97, 0x7C,
	0x29, 0x00, 0x00,  0x02, 0xBF, 0x7C,
	0x29, 0x00, 0x00,  0x02, 0xE5, 0x7C,
	0x29, 0x00, 0x00,  0x02, 0x21, 0x08,
	0x29, 0x00, 0x00,  0x02, 0x4B, 0xA8,
	0x29, 0x00, 0x00,  0x02, 0x72, 0xA8,
	0x29, 0x00, 0x00,  0x02, 0x98, 0xA8,
	0x29, 0x00, 0x00,  0x02, 0xC0, 0xA8,
	0x29, 0x00, 0x00,  0x02, 0xE6, 0xA8,
	0x29, 0x00, 0x00,  0x02, 0x25, 0xF0,
	0x29, 0x00, 0x00,  0x02, 0x23, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0x4F, 0xF0,
	0x29, 0x00, 0x00,  0x02, 0x4D, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0x76, 0xF0,
	0x29, 0x00, 0x00,  0x02, 0x74, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0x9C, 0xF0,
	0x29, 0x00, 0x00,  0x02, 0x9A, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0xC4, 0xF0,
	0x29, 0x00, 0x00,  0x02, 0xC2, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0xEA, 0xF0,
	0x29, 0x00, 0x00,  0x02, 0xE8, 0xE0,
	0x29, 0x00, 0x00,  0x02, 0x24, 0xE8,
	0x29, 0x00, 0x00,  0x02, 0x4E, 0xE8,
	0x29, 0x00, 0x00,  0x02, 0x75, 0xE8,
	0x29, 0x00, 0x00,  0x02, 0x9B, 0xE8,
	0x29, 0x00, 0x00,  0x02, 0xC3, 0xE8,
	0x29, 0x00, 0x00,  0x02, 0xE9, 0xE8,
	0x29, 0x00, 0x00,  0x02, 0xFE, 0x3D,
	0x29, 0x00, 0x00,  0x02, 0x00, 0x05,
	0x29, 0x00, 0x00,  0x02, 0xFE, 0x23,
	0x29, 0x00, 0x00,  0x02, 0x08, 0xC1,
	0x29, 0x00, 0x00,  0x02, 0x0A, 0x60,
	0x29, 0x00, 0x00,  0x02, 0x0B, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x0C, 0x01,
	0x29, 0x00, 0x00,  0x02, 0x0D, 0x80,
	0x29, 0x00, 0x00,  0x02, 0x0E, 0x81,
	0x29, 0x00, 0x00,  0x02, 0x10, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x11, 0x20,
	0x29, 0x00, 0x00,  0x02, 0x12, 0x03,
	0x29, 0x00, 0x00,  0x02, 0x13, 0x80,
	0x29, 0x00, 0x00,  0x02, 0x86, 0x81,
	0x29, 0x00, 0x00,  0x02, 0x88, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x89, 0x20,
	0x29, 0x00, 0x00,  0x02, 0x8A, 0x04,
	0x29, 0x00, 0x00,  0x02, 0x8B, 0x80,
	0x29, 0x00, 0x00,  0x02, 0x14, 0x81,
	0x29, 0x00, 0x00,  0x02, 0x16, 0x18,
	0x29, 0x00, 0x00,  0x02, 0x17, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x18, 0x03,
	0x29, 0x00, 0x00,  0x02, 0x19, 0x04,
	0x29, 0x00, 0x00,  0x02, 0x1A, 0xC0,
	0x29, 0x00, 0x00,  0x02, 0x1B, 0x04,
	0x29, 0x00, 0x00,  0x02, 0x1C, 0x81,
	0x29, 0x00, 0x00,  0x02, 0x1E, 0x18,
	0x29, 0x00, 0x00,  0x02, 0x1F, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x20, 0x05,
	0x29, 0x00, 0x00,  0x02, 0x21, 0x06,
	0x29, 0x00, 0x00,  0x02, 0x22, 0xC0,
	0x29, 0x00, 0x00,  0x02, 0x23, 0x04,
	0x29, 0x00, 0x00,  0x02, 0x51, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x52, 0x54,
	0x29, 0x00, 0x00,  0x02, 0x53, 0x36,
	0x29, 0x00, 0x00,  0x02, 0x54, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x55, 0xCB,
	0x29, 0x00, 0x00,  0x02, 0x56, 0xBC,
	0x29, 0x00, 0x00,  0x02, 0x58, 0x12,
	0x29, 0x00, 0x00,  0x02, 0x59, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x5A, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x5B, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x68, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x69, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x6A, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x6B, 0x21,
	0x29, 0x00, 0x00,  0x02, 0x6C, 0xBC,
	0x29, 0x00, 0x00,  0x02, 0x6D, 0xCB,
	0x29, 0x00, 0x00,  0x02, 0x6E, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x6F, 0x45,
	0x29, 0x00, 0x00,  0x02, 0x70, 0x63,
	0x29, 0x00, 0x00,  0x02, 0x71, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x5F, 0x22,
	0x29, 0x00, 0x00,  0x02, 0x60, 0x11,
	0x29, 0x00, 0x00,  0x02, 0x61, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x62, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x63, 0x11,
	0x29, 0x00, 0x00,  0x02, 0x64, 0x22,
	0x29, 0x00, 0x00,  0x02, 0x33, 0x88,
	0x29, 0x00, 0x00,  0x02, 0x34, 0x88,
	0x29, 0x00, 0x00,  0x02, 0x35, 0x88,
	0x29, 0x00, 0x00,  0x02, 0x36, 0x88,
	0x29, 0x00, 0x00,  0x02, 0x39, 0xFF,
	0x29, 0x00, 0x00,  0x02, 0x3A, 0xF7,
	0x29, 0x00, 0x00,  0x02, 0xFE, 0x00,
	0x29, 0x00, 0x00,  0x02, 0xFE, 0x20,
	0x29, 0x00, 0x00,  0x02, 0x31, 0x22,
	0x29, 0x00, 0x00,  0x02, 0x32, 0x22,
	0x29, 0x00, 0x00,  0x02, 0x44, 0x1E,
	0x29, 0x00, 0x00,  0x02, 0x45, 0x1E,
	0x29, 0x00, 0x00,  0x02, 0x46, 0x1A,
	0x29, 0x00, 0x00,  0x02, 0x47, 0x1A,
	0x29, 0x00, 0x00,  0x02, 0xFE, 0x3D,
	0x29, 0x00, 0x00,  0x02, 0x23, 0x2C,
	0x29, 0x00, 0x00,  0x02, 0xFE, 0x20,
	0x29, 0x00, 0x00,  0x02, 0x2B, 0x75,
	0x29, 0x00, 0x00,  0x02, 0x26, 0x30,
	0x29, 0x00, 0x00,  0x02, 0xFE, 0x3D,
	0x29, 0x00, 0x00,  0x02, 0x20, 0x71,
	0x29, 0x00, 0x00,  0x02, 0xFE, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x35, 0x00,
	0x29, 0x00, 0x00,  0x02, 0x11, 0x00,
	0x29, 0x78, 0x00,  0x02, 0x11, 0x00,
	0x29, 0x0A, 0x00,  0x02, 0x29, 0x00,
	CMD_END
};

static int mipi_dsi_send_cmds(struct sprd_dsi *dsi, void *data)
{
	uint16_t len;
	struct dsi_cmd_desc *cmds = data;

	if ((cmds == NULL) || (dsi == NULL))
		return -1;

	for (; cmds->data_type != CMD_END;) {
		len = (cmds->wc_h << 8) | cmds->wc_l;
		mipi_dsi_dcs_write(dsi, cmds->payload, len);
		if (cmds->wait)
			msleep(cmds->wait);
		cmds = (struct dsi_cmd_desc *)(cmds->payload + len);
	}
	return 0;
}
#endif

static void reset_fpga(void)
{
	sprd_gpio_direction_output(NULL, CONFIG_FPGA_GPIO_RSTN, 1);
	mdelay(1);
	sprd_gpio_direction_output(NULL, CONFIG_FPGA_GPIO_RSTN, 0);
	mdelay(1);
	sprd_gpio_direction_output(NULL, CONFIG_FPGA_GPIO_RSTN, 1);
}

static int rm67200_fpga_init(void)
{
	char *boot_mode = getenv("bootmode");
	pr_info("bootmode: %s\n", boot_mode);

#ifdef CONFIG_FPGA_SINGLE_DISPLAY
	lcd_load_bitfile(bitfile_single, sizeof(bitfile_single));
#else
	if (NULL == boot_mode || !strcmp("alarm", boot_mode) || !strcmp("wdgreboot", boot_mode) || !strcmp("apwdgreboot", boot_mode) \
        || !strcmp("unknowreboot", boot_mode) || !strcmp("panic", boot_mode) || !strcmp("kernel_crash", boot_mode) || !strcmp("manual_dump", boot_mode)) {
		lcd_load_bitfile(bitfile, sizeof(bitfile));
#ifdef CONFIG_SPI_FPGA
		dual_lcd_display = true;
#endif
	} else {
		lcd_load_bitfile(bitfile_single, sizeof(bitfile_single));
	}
#endif

	/* fpga start to send init data to dual lcd */
	reset_fpga();

	return 0;
}

static int rm67200_init(void)
{
	struct sprd_dsi *dsi = &dsi_device;
	struct sprd_dphy *dphy = &dphy_device;

	mipi_dsi_lp_cmd_enable(dsi, true);

	/* do not use this interface function,otherwise fpga may be abnormal */
	//mipi_dsi_send_cmds(dsi, init_data);
	mipi_dsi_set_work_mode(dsi, SPRD_MIPI_MODE_VIDEO);
	mipi_dsi_state_reset(dsi);
	mipi_dphy_hs_clk_en(dphy, true);

	return 0;
}

static int rm67200_readid(void)
{
	pr_info("rm67200 lcd read id ok, forced return LCD ID\n");
	return 0;
}

static int rm67200_power(int on)
{
	pr_info("rm67200_power \n");
	sprd_gpio_request(NULL, CONFIG_LCM_GPIO_RSTN);
	sprd_gpio_direction_output(NULL, CONFIG_LCM_GPIO_RSTN, 1);
	mdelay(5);
	sprd_gpio_direction_output(NULL, CONFIG_LCM_GPIO_RSTN, 0);
	mdelay(5);
	sprd_gpio_direction_output(NULL, CONFIG_LCM_GPIO_RSTN, 1);
	mdelay(5);
  	sprd_gpio_request(NULL, CONFIG_LCM2_GPIO_RSTN);
	sprd_gpio_direction_output(NULL, CONFIG_LCM2_GPIO_RSTN, 1);
	mdelay(5);
	sprd_gpio_direction_output(NULL, CONFIG_LCM2_GPIO_RSTN, 0);
	mdelay(5);
	sprd_gpio_direction_output(NULL, CONFIG_LCM2_GPIO_RSTN, 1);
	mdelay(20);

	return 0;
}

static struct panel_ops rm67200_ops = {
	.init = rm67200_init,
	.fpga_init = rm67200_fpga_init,
	.read_id = rm67200_readid,
	.power = rm67200_power,
};

static struct panel_info rm67200_info = {
	/* common parameters */
	.lcd_name = "lcd_rm67200_mipi_fhd",
	.type = SPRD_PANEL_TYPE_MIPI,
	.bpp = 24,
//	.fps = 60,
	.width = 1080,
	.height = 1920,

	/* DPI specific parameters */
	.pixel_clk = 128000000,
	.rgb_timing = {
		.hfp = 16,
		.hbp = 32,
		.hsync = 4,
		.vfp = 8,
		.vbp = 32,
		.vsync = 4,
	},

	/* MIPI DSI specific parameters */
	.phy_freq = 900000,/*Kbps*/
	.lane_num = 4,
	.work_mode = SPRD_MIPI_MODE_VIDEO,
	.burst_mode = VIDEO_BURST_WITH_SYNC_PULSES,
	.nc_clk_en = false,
};

struct panel_driver rm67200_mipi_driver = {
	.info = &rm67200_info,
	.ops = &rm67200_ops,
};
